<?php $theme_path = base_path().path_to_theme() ?>
<?php
function convertString($str)
{
  $pattern = array( "à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă",
                    "ằ","ắ","ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề",
                    "ế","ệ","ể","ễ",
                    "ì","í","ị","ỉ","ĩ",
                    "ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ",
                    "ờ","ớ","ợ","ở","ỡ",
                    "ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
                    "ỳ","ý","ỵ","ỷ","ỹ",
                    "đ",
                    "À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă",
                    "Ằ","Ắ","Ặ","Ẳ","Ẵ",
                    "È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
                    "Ì","Í","Ị","Ỉ","Ĩ",
                    "Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ","Ờ","Ớ","Ợ","Ở","Ỡ",
                    "Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
                    "Ỳ","Ý","Ỵ","Ỷ","Ỹ",
                    "Đ");
  $replacement = array( "a","a","a","a","a","a","a","a","a","a","a",
                        "a","a","a","a","a","a",
                        "e","e","e","e","e","e","e","e","e","e","e",
                        "i","i","i","i","i",
                        "o","o","o","o","o","o","o","o","o","o","o","o",
                        "o","o","o","o","o",
                        "u","u","u","u","u","u","u","u","u","u","u",
                        "y","y","y","y","y",
                        "d",
                        "A","A","A","A","A","A","A","A","A","A","A","A",
                        "A","A","A","A","A",
                        "E","E","E","E","E","E","E","E","E","E","E",
                        "I","I","I","I","I",
                        "O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O",
                        "U","U","U","U","U","U","U","U","U","U","U",
                        "Y","Y","Y","Y","Y",
                        "D");
  return str_replace($pattern, $replacement, $str);
}

$bpath = base_path();
?>
<?php $base_url = request_uri() ?>
<?php if (preg_match('@nishiki@', $base_url)): ?>
    <?php $_type = 'nishiki' ?>
<?php elseif (preg_match('@honda@', $base_url)): ?>
    <?php $_type = 'honda' ?>
<?php elseif (preg_match('@yamaha@', $base_url)): ?>
    <?php $_type = 'yamaha' ?>
<?php else: ?>
<?php endif ?>

<?php $my_view = views_get_view_result('sanphammoinhat', 'default', $_type) ?>
<?php foreach ($my_view as $item): ?>
    <?php $node_slide_show = intval($item->nid) ?>
    <?php break ?>
<?php endforeach ?>

<div id="container" class="clear-block">
    <div id="header-slide">
      <?php $nnode = @$node ?>
      <?php if ($nnode && ($nnode->type=='xedapdien' || $nnode->type=='xemaydien')): ?>
      <?php else: ?>
        <?php //$nnode = node_load(22) ?>
        <?php $nnode = node_load($node_slide_show) ?>
      <?php endif ?>
      <?php if ($nnode): ?>
        <div id="header-product">
          <?php foreach ($nnode->taxonomy as $tid=>$term): ?>
            <?php $name = strtolower($term->name) ?>
            <p><a href="<?php echo $bpath, 'san-pham/', $name ?>"><img src="<?php echo $theme_path, '/images/logo_', $name, '_trans.png' ?>"/></a></p>
            <?php break ?>
          <?php endforeach ?>
          <p class="title"><?php print_r($nnode->title) ?></p>
          <ul>
            <li>Vận tốc tối đa: <?php print_r($nnode->field_vantoctoida[0]['value']) ?></li>
            <li><?php print_r($nnode->field_sacdien[0]['value']) ?></li>
            <li>Điện áp: <?php print_r($nnode->field_diepap[0]['value']) ?></li>
            <li>Màu:
                <?php foreach ($nnode->attributes as $kattr => $vattr): ?>
                  <?php foreach ($vattr->options as $okey => $ovalue): ?>
                  <?php $name = convertString($ovalue->name) ?>
                  <?php $name = strtolower($name) ?>
                  <?php $name = str_replace(' ', '', $name) ?>
                     <img src="<?php echo $theme_path, '/images/color_', $name, '.png' ?>"/>
                  <?php endforeach; ?>
                <?php endforeach; ?> </li>
          </ul>
        </div>
        <?php $images = $nnode->field_anhsanpham ?>
        <div id="lofslidecontent45" style="width:590px; height:364px; overflow: hidden;">
          <div class="lof-pager">
            <div onclick="return false" href="" class="lof-previous">Prev</div>
            <div onclick="return false" href="" class="lof-next">Next</div>
          </div>

          <div class="lof-navigator-wapper" style="width: 320px; height: 32px; overflow: hidden">
            <div class="lof-navigator-outer">
              <ul class="lof-navigator">
                <?php foreach ($images as $image): ?>
                  <?php if ($image['filepath']): ?>
                    <li style="height: 32px; width: 80px"><?php print theme('imagecache', 'slideshow_product_thumb', $image['filepath'], null, null, null) ?></li>
                  <?php endif ?>
                <?php endforeach ?>
              </ul>
            </div>
          </div> 

          <div class="lof-main-outer">
            <ul class="lof-main-wapper">
              <?php foreach ($images as $image): ?>
                <?php if ($image['filepath']): ?>
                  <li>
                  <?php $link_webpages = base_path().'anh-san-pham?img='.$image['filepath'] ?>
                  <?php /* <a href="<?php print $link_webpages ?>" rel="lightbox"> */ ?>
                     <?php $link_image = $image['filepath'] ?>
                     <?php $base_root = 'http://'.$_SERVER['SERVER_NAME'].'/' ?>
                     <?php if (substr($link_image, 0, 5) != 'http'): ?>
                        <?php $link_image = $base_root.$link_image ?>
                     <?php endif; ?>
                     <a href="<?php print $link_image ?>" rel="lightbox[xxx]">
                        <?php print theme('imagecache', 'slideshow_product', $image['filepath'], $image['alt'], null, null) ?>
                     </a>
                  </li>
                <?php endif ?>
              <?php endforeach ?>
            </ul>
          </div>
        </div>
      <?php endif ?>
    </div>
</div>

<script type="text/javascript">
 $(document).ready( function() {
    var buttons = { previous:$('#lofslidecontent45 .lof-previous') ,
            next:$('#lofslidecontent45 .lof-next') };
    $obj = $('#lofslidecontent45').lofJSidernews( { interval: 7000,
                direction: 'opacitys',
                easing: 'easeInOutExpo',
                duration: 1200,
                auto: true,
                maxItemDisplay: 4,
                navPosition: 'horizontal', // horizontal
                navigatorHeight: 32,
                navigatorWidth: 80,
                mainWidth:590,
                buttons: buttons} );
  });
</script>
